<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=0">
    <title>用户登录</title>
    <link rel="stylesheet" href="/static/style.css">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
<div class="login-page">
    <h1 class="login-title">投票登录</h1>
    <div>
        <form>
            <div class="login-input">
                <label for="jobNumber">工号</label>
                <input id="jobNumber" type="text">
            </div>
            <div class="login-input">
                <label for="password">密码</label>
                <input id="password" type="password">
            </div>
            <!--                <div class="login-input">-->
            <!--                    <label for="verify">验证码</label>-->
            <!--                    <input id="verify" type="text">-->
            <!--                    <img src="#" alt="">-->
            <!--                </div>-->
            <div class="login-submit">
                <button type="button" id="login" class="layui-btn">登录</button>
                <button type="button" id="yiban" class="layui-btn layui-btn-danger">易班</button>
            </div>
        </form>
    </div>
</div>
<script src="/static/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/lib/model/'
    }).use(['jquery', 'layer'], function () {
        var $ = layui.$
            ,layer = layui.layer;
        $(function () {
            layer.alert("登录失败，请重新登录", {
                skin: 'layui-layer-lan'
                ,closeBtn: 0
                ,anim: 1 //动画类型
            });
        });

        $('.login-submit #yiban').click(function () {
            window.location.href = '/user/yiban';
        });

        $('.login-submit #login').click(function () {
            // 获取表单提交的信息
            var jobNumber = $("#jobNumber").val()
                ,password = $("#password").val();
            // 提交表单信息
            $.ajax({
                type: 'POST'
                ,url: '/user/login'
                ,contentType: 'application/json'
                ,data: JSON.stringify({jobNumber: jobNumber, password: password})
                ,success: function (res) {
                    if (res.status == 200) {
                        if (res.data == "" || res.data == null){
                            layer.alert(res.msg, {
                                skin: 'layui-layer-lan'
                                ,closeBtn: 0
                                ,anim: 1 //动画类型
                            });
                        } else {
                            layer.msg(res.msg, {icon: 1, time: 1000, offset: '100px'}, function () {
                                window.location.href = res.data;
                            })
                        }
                    }else {
                        layer.alert(res.msg, {
                            skin: 'layui-layer-red'
                            ,closeBtn: 0
                            ,anim: 0 //动画类型
                        });
                    }
                }
            })
        })
    });
</script>
</body>
</html>